<%--
   slm info
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@ tag language="java" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ attribute name="objectId" required="false" type="java.lang.String"
	description="业务表字段唯一标识。"%>
<%@ attribute name="slmId" required="false" type="java.lang.String"
	description="服务协议id。"%>
<c:if test="${not empty slmId and slmId ne '0'}">
	<div class="box  no-border">
		<div class="header">
			<h3>
				<isperp:relationLabel moduleUrl="slm/serviceAgreement"
					viewUrl="slm/serviceAgreement/view" idValue="${slmId }"
					displayColumn="name" id="slmId"></isperp:relationLabel>
			</h3>
			(<span id="slmReciprocalValue" class="important-info"></span>秒后自动<a
				href="#" onclick="slmSetInterval(true);return false;">刷新服务级别</a>)

		</div>
		<table id="slm-table">
			<tr>
				<td class="td1">&nbsp;</td>
			</tr>
			<tr>
				<td class="td1">目标时长</td>
			</tr>
			<tr>
				<td class="td1">已用时长</td>
			</tr>
			<tr>
				<td class="td1">最终用时</td>
			</tr>
		</table>
	</div>
	<script type="text/javascript">
		var slmSetIntervalCount = 60;
		var slmSetInterval = function(reset) {
			slmSetIntervalCount--;
			if (reset) {
				slmSetIntervalCount = 0;
			}
			if (slmSetIntervalCount != 0) {
				$("#slmReciprocalValue").text(slmSetIntervalCount + 1);
				return;
			}
			slmSetIntervalCount = 60;
			$("#slmReciprocalValue").text(slmSetIntervalCount);
			$.get("slm/serviceTarget/findSlmServiceTargetsValue", {
				agreementId : "${slmId}",
				objectId : "${objectId}"
			}, function(data) {
				$("#slm-table .td").remove();
				var trs = $("#slm-table tr");
				for ( var i = 0; i < data.length; i++) {
					var index = i % 2;
					var item = data[i];
					$(trs[0]).append("<th class='td td1'>" + item.target_name + (item.status ? ((item.status == "正常") ? "(正常)" : "<span class='important-info'>(异常)</span>") : "") + "</td>");
					$(trs[1]).append("<td class='td td0'>" + (item.plan_value || item.target_target) + "</td>");
					$(trs[2]).append("<td class='td td0'>" + (item.current_value || "") + "</td>");
					$(trs[3]).append("<td class='td td0'>" + (item.actual_value || "") + "</td>");
				}
			});
		};
		slmSetInterval(true);
		window.setInterval(slmSetInterval, 1000);
	</script>
</c:if>
